﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hisun.Models;
using Hisun.Controllers;



namespace Hisun.View.UserAccount
{
    public partial class DebugPage :AbcPageBase
    {
        HisunDBDataContext db = new HisunDBDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {


            }
        }

        private void BindMyData()
        {

            GridView_DebugList.DataBind();



        }

        protected void Button_Save_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.Length == 0 || TextBox1.Text.Length > 200)
            {

                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('提交内容为空或超过200字符请修改'); </script>");

            
            }

            if (TextBox1.Text != "")
            {
                TABC_JS_Company myNewRow = new TABC_JS_Company();
                myNewRow.公司ID = DateTime.Now.ToString();
                myNewRow.公司名称 = TextBox1.Text;

                db.TABC_JS_Companies.InsertOnSubmit(myNewRow);
                try
                {
                    db.SubmitChanges();

                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('提交成功'); </script>");
                }
                catch
                {
                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('提交成功'); </script>");

                
                }
            }
        }

        protected void Button_Edit_Command(object sender, CommandEventArgs e)
        {
            string myid = e.CommandArgument.ToString();
            var MyEditRow = (from a in db.TABC_JS_Companies where a.公司ID == myid select a).Single();
               Button btn = (Button)sender;
        DataControlFieldCell dcf = (DataControlFieldCell)btn.Parent;
        GridViewRow gvr = (GridViewRow)dcf.Parent;
            try
            {

                MyEditRow.公司名称 = ((TextBox)gvr.Cells[1].FindControl("TextBox2")).Text;

                db.SubmitChanges();
            }
            catch
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('失败'); </script>");
            }
        }




    }
}
